#define _CRT_SECURE_NO_WARNINGS 1
#pragma once
#include<iostream>
#include<assert.h>
using namespace std;

namespace lhl {
	class string {
	private:
		char* _str;
		size_t _size;
		size_t _capacity;
		const static size_t npos = -1;
	public:
		typedef char* iterator;
		typedef const char* const_iterator;


		string(const char* str = "") {
			_size = strlen(str);
			_capacity = _size;
			_str = new char[_capacity + 1];
			strcpy(_str, str);
		}

		string(const string& s) {
			_str = new char[s._capacity + 1];
			strcpy(_str, s._str);
			_size = s._size;
			_capacity = s._capacity;
		}

		~string() {
			delete[] _str;
			_str = nullptr;
			_size = _capacity = 0;
		}

		string& operator=(const string& s);

		iterator begin() {
			return _str;
		}

		iterator end() {
			return _str + _size;
		}

		const_iterator begin() const
		{
			return _str;
		}

		const_iterator end() const
		{
			return _str + _size;
		}

		const char* c_str() {
			return _str;
		}

		char& operator[](size_t i);
		const char& operator[](size_t i) const;

		void reserve(size_t i);
		void push_back(char ch);
		void append(const char* str);

		string& operator+=(const char* str);
		string& operator+=(char ch);

		size_t getCapacity() {
			return _capacity;
		}

		size_t getSize() {
			return _size;
		}

		void insert(size_t pos, char ch);
		void insert(size_t pos, const char* str);
		void erase(size_t pos, size_t len = npos);
		void swap(string& s);
		size_t find(char ch, size_t pos = npos);
		size_t find(const char* str, size_t pos = npos);
		string substr(size_t pos = 0, size_t len = npos);

		void clear();


	};

	ostream& operator<<(ostream& out, const string& s);
	istream& operator>>(istream& in, string& s);
}


